<?php
// αν έχει γίνει η καταχώρηση εμφανίζεται το αντίστοιχο μήνυμα, αλλιώς εμφανίζεται η φόρμα καταχώρησης
if ($_GET['userRegistration'] == "success") 
{
	echo 'Your registration was succesfull';
} 
else if($_GET['userRregistration'] == "failed") 
{
	echo 'Error: Your registration was not succesfull';
}

else
{
?>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script>
function passwordStrength(password)
{
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 3) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 7) score++;

	 document.getElementById("passwordDescription").innerHTML = desc[score];
	 document.getElementById("passwordStrength").className = "strength" + score;
}
</script>
<script language="javascript">

	function check_validation()
	{
		// validation for username
		if(document.getElementById("user_name").value.split(" ").join("") == "")
		{
			alert("Please enter username.");
			document.getElementById("user_name").focus();
			//jQuery("#user_name_error_value").html("Please enter username.");
			//jQuery("#user_name_error").fadeIn("slow");
			return false;
		}
		else
		{
			//jQuery("#user_name_error").fadeOut("slow");
		}
		
		// validation for users password
		if ($("#user_passwd").val() == "") {
			alert("Please enter a password.");
			$("#user_passwd").focus();
			jQuery("#user_passwd_error_value").html("Please enter a password.");
			//jQuery("#user_passwd_error").fadeIn("slow");
			return false;
		} else if (($("#user_passwd").val().length < 7) || ($("#user_passwd").val().length > 15)) {
			alert("You password should have 7 to 15 characters.");
			$("#user_passwd").focus();
			jQuery("#user_passwd_error_value").html("You password should have 7 to 15 characters.");
			//jQuery("#user_passwd_error").fadeIn("slow");
			return false;
		}
		else
		{
			//jQuery("#user_passwd_error").fadeOut("slow");
		}
			if(document.getElementById('user_passwd').value!=document.getElementById('confirm_password').value)
			{
			document.getElementById('user_passwd_error_value').innerHTML="Confirm Password not match";
			$('#user_passwd_error').show();
			document.getElementById('confirm_password').focus();
			return false;
			}
		
		// validation for users first name
		if(document.getElementById("user_fname").value.split(" ").join("") == "")
		{
			alert("Please enter your first name.");
			document.getElementById("user_fname").focus();
			jQuery("#user_fname_error_value").html("Please enter your first name.");
			//jQuery("#user_fname_error").fadeIn("slow");
			return false;
		}
		
		// validation for users last name
		if(document.getElementById("user_lname").value.split(" ").join("") == "")
		{
			alert("Please enter your surname.");
			document.getElementById("user_lname").focus();
			jQuery("#user_lname_error_value").html("Please enter your surname.");
			//jQuery("#user_lname_error").fadeIn("slow");
			return false;
		}
		
		//http://www.w3resource.com/javascript/form/phone-no-validation.php
		// validation for users primary phone number
		if(document.getElementById("user_phone1").value.split(" ").join("") == "")
		{
			alert("Please enter your primary phone number.");
			document.getElementById("user_phone1").focus();
			jQuery("#user_phone1_error_value").html("Please enter your primary phone number.");
			//jQuery("#user_phone1_error").fadeIn("slow");
			return false;
		} else if (($("#user_phone1").val().length < 8)) {
			alert("You phone number should have minimum 8 characters.");
			$("#user_phone1").focus();
			jQuery("#user_phone1_error_value").html("You phone number should have minimum 8 characters.");
			//jQuery("#user_phone1_error").fadeIn("slow");
			return false;
		}

		// validation for users secondary phone number
		if(document.getElementById("user_phone2").value.split(" ").join("") == "")
		{
			alert("Please enter your mobile number.");
			document.getElementById("user_phone2").focus();
			jQuery("#user_phone2_error_value").html("Please enter your mobile number.");
			//jQuery("#user_phone2_error").fadeIn("slow");
			return false;
		}
		
		// validation for users location
		if(document.getElementById("autocomplete").value.split(" ").join("") == "")
		{
			alert("Please enter your location.");
			document.getElementById("autocomplete").focus();
			jQuery("#autocomplete_error_value").html("Please enter your location.");
			//jQuery("#autocomplete_error").fadeIn("slow");
			return false;
		}
		
		if(document.getElementById("user_email").value.split(" ").join("") == "")
			{
				alert("Please enter your email address.");
				//alert('Please enter your email address.'); 
				document.getElementById("user_email").focus();
				jQuery("#user_email_error_value").html("Please enter your location.");
				//jQuery("#user_email_error").fadeIn("slow");
				return false;
			}
			else
			{
				var emailPat=/^(.+)@(.+)$/
				var matchArray=document.getElementById("user_email").value.match(emailPat)
			
				if (matchArray==null) 
				{
					//alert("")
					alert('The email address that you have entered is invalid.'); 
					document.getElementById("user_email").focus();
					jQuery("#user_email_error_value").html("The email address that you have entered is invalid.");
					//jQuery("#user_email_error").fadeIn("slow");
					return false;
				}
		}
		if(document.getElementById("user_website").value.split(" ").join("") == "")
		{
			alert("Please enter your website url.");
			document.getElementById("user_website").focus();
			jQuery("#user_website_error_value").html("The email address that you have entered is invalid.");
			//jQuery("#user_website_error").fadeIn("slow");
			return false;
		}
		
			return true;
}
	

	function check_validation_of_field($value_of_field,$type_of_field)
	{
		if($value_of_field != "")
		{
			$.post( "http://192.185.116.17/~wwwmsc/includes/check_validation.php?field_type="+$type_of_field+"&field_value="+$value_of_field, function( data ) {
				if($type_of_field == "user_name")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_name_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_name_error_value").html("The username that you have entered already exists, Please enter different username.");
						jQuery("#user_name_error").fadeIn("slow");
					}
				}
				else if($type_of_field == "user_email")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_email_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_email_error_value").html("The email that you have entered already exists, Please enter different email.");
						jQuery("#user_email_error").fadeIn("slow");
					}
				}
			});
		}
	}

</script>
<?php if($_REQUEST['captch']==1){?>
<span style="color:#FF0000">Λάθος Captch Δοκιμάστε ξανά</span>
<bR /><br />

<? extract($_SESSION['DATA']); $_SESSION['DATA']=""; }?>
Νέα Εγγραφή
<form name="UserRegistrationForm" action="includes/UserRegister.php" method="POST" onsubmit="javascript:return check_validation();">
	<table width="100%" border="0">
    	<tr>
        	<td width="100%" align="right">Τύπος Λογαριασμού:</td>
            <td width="100%" align="left">
                <select name="user_level" id="user_level">
                    <option value="3" <?php if($user_level==3){?> selected="selected"<? }?>>Εταιρία</option>
                    <option value="4" <?php if($user_level==4){?> selected="selected"<? }?>>Ιδιώτης</option>
                </select>
            </td>
        </tr>             
    	<tr>
        	<td width="100%" align="right">Username:</td>
            <td width="100%" align="left"><input type="text" id="user_name" name="user_name" value="<?php echo $user_name;?>"  size="50" onblur="check_validation_of_field(this.value,'user_name')"></td>
        </tr>
        <tr id="user_name_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_name_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right" valign="top">Κωδικός:</td>
            <td width="100%" align="left"><input type="password" id="user_passwd" name="user_passwd"  size="50" onKeyUp="passwordStrength(this.value)">
			<bR /><label for="passwordStrength">Password strength</label>
			<div id="passwordDescription">Password not entered</div>
			<div id="passwordStrength" class="strength0"></div>
		</td>
        </tr>
         
        	<tr>
        	<td width="100%" align="right"> Επιβεβαίωση Κωδικού :</td>
            <td width="100%" align="left"><input type="password" id="confirm_password" name="confirm_password"  size="50"></td>
        </tr>     
        <tr id="user_passwd_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_passwd_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Όνομα:</td>
            <td width="100%" align="left"><input type="text" id="user_fname" name="user_fname" value="<?php echo $user_fname;?>"  size="50"  onfocus="check_confirm_pass();"></td>
        </tr>       
        <tr id="user_fname_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_fname_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Επώνυμο:</td>
            <td width="100%" align="left"><input type="text" id="user_lname" name="user_lname" value="<?php echo $user_lname;?>"  size="50"></td>
        </tr>   
        <tr id="user_lname_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_lname_error_value"></td>
        </tr>
    	<?php /*?><tr>
        	<td width="100%" align="right">Διεύθυνση:</td>
            <td width="100%" align="left"><input type="text" id="user_locid" name="user_locid"  size="50"></td>
        </tr><?php */?>
    	<tr>
        	<td width="100%" align="right">Τηλέφωνο:</td>
            <td width="100%" align="left"><input type="text" id="user_phone1" name="user_phone1" value="<?php echo $user_phone1;?>"  size="50"></td>
        </tr>
        <tr id="user_phone1_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_phone1_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Κινητό:</td>
            <td width="100%" align="left"><input type="text" id="user_phone2" name="user_phone2" value="<?php echo $user_phone2;?>"  size="50"></td>
        </tr>
        <tr id="user_phone2_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
            	
        	<td width="100%" align="left" style="color:#FF0000;" id="user_phone2_error_value"></td>
        </tr>
        <tr>
        	<td width="100%" align="right">Διεύθυνση:</td>
            <td width="100%" align="left">
                <div id="locationField">
                  <input id="autocomplete" placeholder="Εισάγετε τη διεύθυνση σας"
                         onFocus="geolocate()" name="autocomplete" type="text" style="width:69%;"></input>
                </div>
            
                <table id="address" hidden="true">
                  <tr>
                    <td class="label">Διεύθυνση</td>
                    <td class="slimField"><input class="field" id="street_number" name="street_number" disabled="true"></input></td>
                    <td class="wideField" colspan="2"><input class="field" id="route" name="route" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Πόλη</td>
                    <td class="wideField" colspan="3"><input class="field" id="locality" name="locality" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Νομός</td>
                    <td class="slimField"><input class="field" id="administrative_area_level_1" name="administrative_area_level_1" disabled="true"></input></td>
                    <td class="label">Τ.Κ.</td>
                    <td class="wideField"><input class="field" id="postal_code" name="postal_code" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Country</td>
                    <td class="wideField" colspan="3"><input class="field"
                          id="country" disabled="true"></input></td>
                  </tr>
                </table>
            </td>
        </tr>
        <tr id="autocomplete_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="autocomplete_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Φύλλο:</td>
            <td width="100%" align="left">
             <select name="user_gender" id="user_gender">
                    <option value="male" <?php if($user_gender=="male"){?> selected="selected"<? }?>>Άνδρας</option>
                    <option value="female" <?php if($user_gender=="female"){?> selected="selected"<? }?>>Γυναίκα</option>
             </select>
        </tr>
    	<tr>
        	<td width="100%" align="right">Email:</td>
            <td width="100%" align="left"><input type="text" id="user_email" name="user_email" value="<?php echo $user_email;?>"  size="50" onblur="check_validation_of_field(this.value,'user_email')"></td>
        </tr> 
        <tr id="user_email_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_email_error_value"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Ιστότοπος:</td>
            <td width="100%" align="left"><input type="text" id="user_website" name="user_website" value="<?php echo $user_website;?>"  size="50"></td>
        </tr> 
        <tr id="user_website_error" style="display:none;">
        	<td width="100%" align="right">&nbsp;</td>
        	<td width="100%" align="left" style="color:#FF0000;" id="user_website_error_value"></td>
        </tr>
        <tr>
        	<td width="100%" align="right">&nbsp;</td>
            <td width="100%" align="left"><?php
          require_once('recaptchalib.php');
          $publickey = "6LfLKewSAAAAANdHoxBoBq2iuVbsHdEDRPDezeAf"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
</td>
        </tr> 
        	
    	<tr>
        	<td width="100%" align="right">&nbsp;</td>
            <td width="100%" align="left"><input type="Submit"  value="Καταχώρηση"></td>
        </tr> 
    </table>
</form>
<?php
}
?>
<script>	function check_confirm_pass()
{

if(document.getElementById('user_passwd').value!=document.getElementById('confirm_password').value)
{
document.getElementById('user_passwd_error_value').innerHTML="Confirm Password not match";
$('#user_passwd_error').show();
document.getElementById('confirm_password').focus();
}

}</script>